package domain;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 购物种类
 */
public class ShoppingItem {
    //水果
    private Fruits fruits;
    //数量
    private int quantity;

    public ShoppingItem(Fruits fruits, int quantity) {
        this.fruits = fruits;
        this.quantity = quantity;
    }

    public Fruits getFruits() {
        return fruits;
    }

    public void setFruits(Fruits fruits) {
        this.fruits = fruits;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    /**
     * 计算该项商品的价格
     * @return 商品价格
     */
    public BigDecimal calculatePrice() {
        // 单价乘以数量
        return fruits.getPrice()
                .multiply(new BigDecimal(quantity))
                .setScale(2, RoundingMode.HALF_UP);
    }
}
